package common

import (
	"fmt"
	"reflect"
)

func DumpValue(v interface{}) string {
	if v == nil {
		return "nil"
	}

	t := reflect.TypeOf(v)

	var vs string
	if gos, ok := v.(fmt.GoStringer); ok {
		vs = gos.GoString()
	} else if s, ok := v.(fmt.Stringer); ok {
		vs = fmt.Sprintf("%q", s.String())
	} else if s, ok := v.(string); ok {
		vs = fmt.Sprintf("%q", s)
	} else {
		vs = fmt.Sprintf("%v", v)
	}

	return fmt.Sprintf("%s (type=%s)", vs, t)
}
